package com.tian.controller.manage;

import com.tian.pojo.bo.ItemManageBO;
import com.tian.pojo.vo.ItemManageVO;
import com.tian.pojo.vo.UserManageVO;
import com.tian.service.manage.ItemManageService;
import com.tian.utils.JSONResult;
import com.tian.utils.PagedGridResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("manage")
public class ItemManageController {

    @Autowired
    private ItemManageService itemManageService;

    @GetMapping("/getItemManage")
    public JSONResult getItemManage(
            @RequestParam Integer page,
            @RequestParam Integer pageSize){
        if (page==null){
            page=1;
        }
        if (pageSize==null){
            pageSize=10;
        }

        PagedGridResult gridResult = itemManageService.queryPagedItemManage(page, pageSize);

        return JSONResult.ok(gridResult);

    }

    @GetMapping("/getGoodManageByGoodName")
    public JSONResult getGoodManageByGoodName(@RequestParam String goodname){
        if (StringUtils.isBlank(goodname)){
            JSONResult.errorMsg("用户名不能为空");
        }
        List<ItemManageVO> list = itemManageService.getGoodManageByGoodName(goodname);
        return JSONResult.ok(list);
    }

    @PostMapping("/updateItemManage")
    public JSONResult updateItemManage(@RequestBody ItemManageBO itemManageBO){
        itemManageService.updateItemManage(itemManageBO);
        return JSONResult.ok();
    }
}
